<form class="layui-form">
    <table class="layui-table layui-table-content" lay-skin="nob">
        <tbody>

        <tr>
            <th width="150"><span class="red">*</span>普通上传</th>
            <td>
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="btn_upload">上传图片</button>
                    <div class="layui-upload-list">
                        <img id="img_upload" class="layui-upload-img"
                             src="/resources/images/administrate/upload_default.png"
                             style="width: 92px; height: 92px; margin: 0 10px 10px 0;">
                        <p id="text_upload"></p>
                    </div>
                </div>
            </td>
        </tr>


        <tr>
            <th width="150"><span class="red">*</span>多图上传</th>
            <td>
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="btn_upload2">多图片上传</button>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px; display: none;">
                        预览图：
                        <div class="layui-upload-list" id="div_upload2"></div>
                    </blockquote>
                </div>
            </td>
        </tr>


        <tr>
            <th width="150"><span class="red">*</span>编辑器</th>
            <td>
                <div id="editor"></div>
            </td>
        </tr>
        </tbody>
    </table>
    <div class="layui-button">
        <button class="layui-btn" style=" min-width: 150px;" lay-submit lay-filter="formSubmit">提 交</button>
        <div class="layui-btn" style=" min-width: 150px;" onclick="location.href='/administrate/menu'">返 回</div>
    </div>
</form>
</div>
<#macro script>
    <script src="/resources/plugin/ueditor/ueditor.config.js"></script>
    <script src="/resources/plugin/ueditor/ueditor.all.min.js"></script>
    <script>
        UE.getEditor('editor');
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;


            /*普通图片上传*/
            var uploadInst = upload.render({
                elem: '#btn_upload'
                , url: '/ueditor?action=uploadimage'
                , field: 'upfile'
                , accept: 'images'
                , exts: 'jpg|png|gif|bmp|jpeg'
                , size: 1024
                , before: function () {
                    layer.load(2);

                }
                , done: function (res) {
                    layer.closeAll('loading');
                    if (res.state == "SUCCESS") {
                        layer.msg('上传成功');
                        $("#img_upload").attr("src", res.url);
                    }
                    else {
                        $("#img_upload").attr("src", "/resources/images/administrate/upload_error.png");
                        layer.msg(res.state);
                    }
                }
                , error: function () {
                    layer.closeAll('loading');
                    $("#img_upload").attr("src", "/resources/images/administrate/upload_error.png");
                    var text = $('#text_upload');
                    text.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload" style="color:#ffffff;">重试</a>');
                    text.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

            /*多图片上传*/
            upload.render({
                elem: '#btn_upload2'
                , url: '/ueditor?action=uploadimage'
                , field: 'upfile'
                , accept: 'images'
                , exts: 'jpg|png|gif|bmp|jpeg'
                , size: 1024
                , multiple: true
                , before: function () {
                    layer.load(2);
                    $("#div_upload2").parent().show();
                }
                , done: function (res) {
                    layer.closeAll('loading');
                    if (res.state == "SUCCESS") {
                        $('#div_upload2').append('<img src="' + res.url + '" alt="' + res.original + '" class="layui-upload-img">')
                    }
                    else {
                        $('#div_upload2').append('<img src="/resources/images/administrate/upload_error.png" alt="' + res.state + '" class="layui-upload-img">')
                    }
                }
                , error: function () {
                    layer.closeAll('loading');
                    $('#div_upload2').append('<img src="/resources/images/administrate/upload_error.png" class="layui-upload-img">')
                }
            })


        });
    </script>
</#macro>